﻿Imports MySql.Data.MySqlClient
Public Class Form1
    Public Quest_Method As String
    Public Quest_RequiredRace As String
    Public Quest_Entry As String
    Public Quest_Title As String
    Public Quest_Details As String
    Public editor_version As String = "1.0.0"
    Public connStr As String
    Public Quest_SuggestedPlayers As String
    Public Quest_SuggestedPlayersIndex As String
    Public Quest_MinLevel As String
    Public Quest_MaxLevel As String
    Public Quest_Level As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Trinity Quest Editor v" + editor_version
        Quest_RequiredRace = 0
        Dialog1.sqlUser.Text = My.Settings.sqlUsername
        Dialog1.sqlPass.Text = My.Settings.sqlPassword
        Dialog1.sqlHost.Text = My.Settings.DbHost
        Dialog1.sqlPort.Text = My.Settings.DbPort
        ComboBox1.SelectedIndex = 2
        If My.Settings.FirstRun = "false" Then
            My.Settings.FirstRun = "true"
            My.Settings.Save()
            Dialog2.ShowDialog()
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 0 Then
            Quest_Method = 0
        ElseIf ComboBox1.SelectedIndex = 1 Then
            Quest_Method = 1
        ElseIf ComboBox1.SelectedIndex = 2 Then
            Quest_Method = 2
        End If
    End Sub
    Private Sub Human_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Human_Checkbox.CheckedChanged
        If Human_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 1
        Else
            Quest_RequiredRace = Quest_RequiredRace - 1
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Orc_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Orc_Checkbox.CheckedChanged
        If Orc_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 2
        Else
            Quest_RequiredRace = Quest_RequiredRace - 2
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Dwarf_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dwarf_Checkbox.CheckedChanged
        If Dwarf_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 4
        Else
            Quest_RequiredRace = Quest_RequiredRace - 4
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub NightElf_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NightElf_Checkbox.CheckedChanged
        If NightElf_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 8
        Else
            Quest_RequiredRace = Quest_RequiredRace - 8
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Undead_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Undead_Checkbox.CheckedChanged
        If Undead_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 16
        Else
            Quest_RequiredRace = Quest_RequiredRace - 16
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Tauren_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tauren_Checkbox.CheckedChanged
        If Tauren_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 32
        Else
            Quest_RequiredRace = Quest_RequiredRace - 32
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Gnome_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Gnome_Checkbox.CheckedChanged
        If Gnome_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 64
        Else
            Quest_RequiredRace = Quest_RequiredRace - 64
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Troll_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Troll_Checkbox.CheckedChanged
        If Troll_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 128
        Else
            Quest_RequiredRace = Quest_RequiredRace - 128
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub BloodElf_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BloodElf_Checkbox.CheckedChanged
        If BloodElf_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 512
        Else
            Quest_RequiredRace = Quest_RequiredRace - 512
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Draenei_Checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Draenei_Checkbox.CheckedChanged
        If Draenei_Checkbox.Checked = True Then
            Quest_RequiredRace = Quest_RequiredRace + 1024
        Else
            Quest_RequiredRace = Quest_RequiredRace - 1024
        End If
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Orc_Checkbox.CheckState = CheckState.Checked
        Undead_Checkbox.CheckState = CheckState.Checked
        Tauren_Checkbox.CheckState = CheckState.Checked
        Troll_Checkbox.CheckState = CheckState.Checked
        BloodElf_Checkbox.CheckState = CheckState.Checked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Human_Checkbox.CheckState = CheckState.Checked
        Dwarf_Checkbox.CheckState = CheckState.Checked
        NightElf_Checkbox.CheckState = CheckState.Checked
        Gnome_Checkbox.CheckState = CheckState.Checked
        Draenei_Checkbox.CheckState = CheckState.Checked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Human_Checkbox.CheckState = CheckState.Checked
        Orc_Checkbox.CheckState = CheckState.Checked
        Dwarf_Checkbox.CheckState = CheckState.Checked
        NightElf_Checkbox.CheckState = CheckState.Checked
        Undead_Checkbox.CheckState = CheckState.Checked
        Tauren_Checkbox.CheckState = CheckState.Checked
        Gnome_Checkbox.CheckState = CheckState.Checked
        Troll_Checkbox.CheckState = CheckState.Checked
        BloodElf_Checkbox.CheckState = CheckState.Checked
        Draenei_Checkbox.CheckState = CheckState.Checked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Orc_Checkbox.CheckState = CheckState.Unchecked
        Undead_Checkbox.CheckState = CheckState.Unchecked
        Tauren_Checkbox.CheckState = CheckState.Unchecked
        Troll_Checkbox.CheckState = CheckState.Unchecked
        BloodElf_Checkbox.CheckState = CheckState.Unchecked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Human_Checkbox.CheckState = CheckState.Unchecked
        Dwarf_Checkbox.CheckState = CheckState.Unchecked
        NightElf_Checkbox.CheckState = CheckState.Unchecked
        Gnome_Checkbox.CheckState = CheckState.Unchecked
        Draenei_Checkbox.CheckState = CheckState.Unchecked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Human_Checkbox.CheckState = CheckState.Unchecked
        Orc_Checkbox.CheckState = CheckState.Unchecked
        Dwarf_Checkbox.CheckState = CheckState.Unchecked
        NightElf_Checkbox.CheckState = CheckState.Unchecked
        Undead_Checkbox.CheckState = CheckState.Unchecked
        Tauren_Checkbox.CheckState = CheckState.Unchecked
        Gnome_Checkbox.CheckState = CheckState.Unchecked
        Troll_Checkbox.CheckState = CheckState.Unchecked
        BloodElf_Checkbox.CheckState = CheckState.Unchecked
        Draenei_Checkbox.CheckState = CheckState.Unchecked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
    End Sub
    Private Sub questEntry_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles questEntry.TextChanged
        Quest_Entry = questEntry.Text
    End Sub
    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Dim Quest_Info As String = Quest_Entry + "|" + Quest_Method + "|" + Quest_RequiredRace + "|" + Quest_Title + "|" + Quest_Details + "|" + Quest_MinLevel + "|" + Quest_MaxLevel + "|" + Quest_Level + "|" + Quest_SuggestedPlayersIndex
        Dim Stream As New IO.StreamWriter(SaveFileDialog1.FileName)
        Stream.Write(Quest_Info)
        Stream.Close()
    End Sub

    Private Sub SaveQuestFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveQuestFileToolStripMenuItem.Click
        SaveFileDialog1.ShowDialog()
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        Human_Checkbox.CheckState = CheckState.Unchecked
        Orc_Checkbox.CheckState = CheckState.Unchecked
        Dwarf_Checkbox.CheckState = CheckState.Unchecked
        NightElf_Checkbox.CheckState = CheckState.Unchecked
        Undead_Checkbox.CheckState = CheckState.Unchecked
        Tauren_Checkbox.CheckState = CheckState.Unchecked
        Gnome_Checkbox.CheckState = CheckState.Unchecked
        Troll_Checkbox.CheckState = CheckState.Unchecked
        BloodElf_Checkbox.CheckState = CheckState.Unchecked
        Draenei_Checkbox.CheckState = CheckState.Unchecked
        Label3.Text = "Race Bits: " + Quest_RequiredRace
        questEntry.Text = ""
        questTitle.Text = ""
        questDetails.Text = ""
        questLevel.Text = ""
        questMinLevel.Text = ""
        questMaxLevel.Text = ""
        questLevel.Text = ""
        ComboBox2.SelectedIndex = 0
        ComboBox1.SelectedIndex = 0
        Quest_Entry = 0
        Quest_Title = ""
        Quest_Details = ""
        Quest_MinLevel = 0
        Quest_MaxLevel = 0
        Quest_Level = 0
        Quest_SuggestedPlayers = 0
        Quest_SuggestedPlayersIndex = 0
        Me.Text = "Trinity Quest Editor v" + editor_version
    End Sub

    Private Sub LoadQuestFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadQuestFileToolStripMenuItem.Click
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        Dim Reader As New IO.StreamReader(OpenFileDialog1.FileName)
        Dim Quest_File As String = Reader.ReadToEnd
        Reader.Close()
        Dim QuestArray() As String = Quest_File.Split("|")
        questEntry.Text = QuestArray(0)
        ComboBox1.SelectedIndex = QuestArray(1)
        Select Case QuestArray(2)
            Case 1791
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Tauren_Checkbox.CheckState = CheckState.Checked
                Gnome_Checkbox.CheckState = CheckState.Checked
                Troll_Checkbox.CheckState = CheckState.Checked
                BloodElf_Checkbox.CheckState = CheckState.Checked
                Draenei_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 0
                Human_Checkbox.CheckState = CheckState.Unchecked
                Orc_Checkbox.CheckState = CheckState.Unchecked
                Dwarf_Checkbox.CheckState = CheckState.Unchecked
                NightElf_Checkbox.CheckState = CheckState.Unchecked
                Undead_Checkbox.CheckState = CheckState.Unchecked
                Tauren_Checkbox.CheckState = CheckState.Unchecked
                Gnome_Checkbox.CheckState = CheckState.Unchecked
                Troll_Checkbox.CheckState = CheckState.Unchecked
                BloodElf_Checkbox.CheckState = CheckState.Unchecked
                Draenei_Checkbox.CheckState = CheckState.Unchecked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 1
                Human_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 2
                Orc_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 4
                Dwarf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 8
                NightElf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 16
                Undead_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 32
                Tauren_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 64
                Gnome_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 128
                Troll_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 512
                BloodElf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 1024
                Draenei_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 3
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 7
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 15
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 31
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 63
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Tauren_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 127
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Tauren_Checkbox.CheckState = CheckState.Checked
                Gnome_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 255
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Tauren_Checkbox.CheckState = CheckState.Checked
                Gnome_Checkbox.CheckState = CheckState.Checked
                Troll_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
            Case 767
                Human_Checkbox.CheckState = CheckState.Checked
                Orc_Checkbox.CheckState = CheckState.Checked
                Dwarf_Checkbox.CheckState = CheckState.Checked
                NightElf_Checkbox.CheckState = CheckState.Checked
                Undead_Checkbox.CheckState = CheckState.Checked
                Tauren_Checkbox.CheckState = CheckState.Checked
                Gnome_Checkbox.CheckState = CheckState.Checked
                Troll_Checkbox.CheckState = CheckState.Checked
                BloodElf_Checkbox.CheckState = CheckState.Checked
                Label3.Text = "Race Bits: " + Quest_RequiredRace
        End Select
        questTitle.Text = QuestArray(3)
        Quest_Title = QuestArray(3)
        questDetails.Text = QuestArray(4)
        Quest_Details = QuestArray(4)
        Quest_MinLevel = QuestArray(5)
        questMinLevel.Text = QuestArray(5)
        questMaxLevel.Text = QuestArray(6)
        Quest_MaxLevel = QuestArray(6)
        Quest_Level = QuestArray(7)
        questLevel.Text = QuestArray(7)
        Quest_SuggestedPlayersIndex = QuestArray(8)
        ComboBox2.SelectedIndex = Quest_SuggestedPlayersIndex
        Me.Text = "Trinity Quest Editor v" + editor_version + " - Quest#" + Quest_Entry + " - " + Quest_Title
    End Sub

    Private Sub questTitle_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles questTitle.TextChanged
        Quest_Title = questTitle.Text
        Me.Text = "Trinity Quest Editor v" + editor_version + " - Quest#" + Quest_Entry + " - " + Quest_Title
    End Sub

    Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
        Dialog1.ShowDialog()
    End Sub

    Private Sub ScriptExecutionSettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScriptExecutionSettingsToolStripMenuItem.Click
        Dialog3.ShowDialog()
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Select Case ComboBox2.SelectedIndex
            Case 0
                Quest_SuggestedPlayers = 2
                Quest_SuggestedPlayersIndex = 0
            Case 1
                Quest_SuggestedPlayers = 3
                Quest_SuggestedPlayersIndex = 1
            Case 2
                Quest_SuggestedPlayers = 5
                Quest_SuggestedPlayersIndex = 2
            Case 3
                Quest_SuggestedPlayers = 10
                Quest_SuggestedPlayersIndex = 3
            Case 4
                Quest_SuggestedPlayers = 25
                Quest_SuggestedPlayersIndex = 4
        End Select
    End Sub

    Private Sub questMinLevel_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles questMinLevel.TextChanged
        Quest_MinLevel = questMinLevel.Text
    End Sub

    Private Sub questMaxLevel_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles questMaxLevel.TextChanged
        Quest_MaxLevel = questMaxLevel.Text
    End Sub

    Private Sub questLevel_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles questLevel.TextChanged
        Quest_Level = questLevel.Text
    End Sub
End Class